//
// Created by Administrator on 2023/5/28.
//
#pragma once
#ifndef MINI_BUTTON_H
#define MINI_BUTTON_H

#include <QPushButton>
#include <QMouseEvent>
#include "../../Qss/Mini_Button_Q.h"


template <typename Owner>
class Mini_Button: public QPushButton
{
public:
    Mini_Button(Owner* owner);


    Mini_Button(Owner* owner, bool activation);


    ~Mini_Button();


    void mousePressEvent(QMouseEvent* event);
    void mouseReleaseEvent(QMouseEvent* event);



    void Profile(bool activation);


    void Redraw();



private:
    Mini_Button();


    Owner* owner;


    bool mini_press {false};
    bool activation;

    int width {15};
    int height {15};

};
template <typename Owner>
Mini_Button<Owner>::Mini_Button(Owner* owner):
        owner(owner), activation(false)
{
    this->Profile(this->activation);
}


template <typename Owner>
Mini_Button<Owner>::Mini_Button(Owner* owner, bool activation):
        owner(owner), activation(activation)
{
    this->Profile(this->activation);
}


template <typename Owner>
Mini_Button<Owner>::Mini_Button(){}


template <typename Owner>
Mini_Button<Owner>::~Mini_Button(){}


template <typename Owner>
void Mini_Button<Owner>::Profile(bool activation)
{
    if (!activation)
    {
        this->setParent(this->owner);


        this->resize(this->width, this->height);


        this->move(this->owner->geometry().width() - 65, 7);


        this->setMouseTracking(true);


        this->setObjectName("Mini_Button");


        this->setStyleSheet(mini_q_f);
    }
    else
    {
        this->setParent(this->owner);


        this->resize(this->width, this->height);


        this->move(this->owner->geometry().width() - 65, 7);


        this->setMouseTracking(true);


        this->setObjectName("Mini_Button");


        this->setStyleSheet(mini_q_t);
    }
}


template <typename Owner>
void Mini_Button<Owner>::mousePressEvent(QMouseEvent* event)
{
    if (event->button() == Qt::LeftButton && !this->activation)
    {
        this->mini_press =true;
    }
}


template <typename Owner>
void Mini_Button<Owner>::mouseReleaseEvent(QMouseEvent* event)
{
    if(this->mini_press && !this->activation)
    {
        this->owner->Widget_Mini();
    }
}


template <typename Owner>
void Mini_Button<Owner>::Redraw()
{
    this->move(this->owner->geometry().width() - 65, 7);
}




#endif //MINI_BUTTON_H
